#include <bits/stdc++.h>
// 二维费用01背包问题
// Time Complexity: O(N*M*K)
using namespace std;
const int N = 110, M = 1010, K = 510;

int balls[N], hits[N];
int f[M][K];
int main() {
  int n, pokeball, initial_hp;
  cin >> pokeball >> initial_hp >> n;
  for (int i = 1; i <= n; ++i) cin >> balls[i] >> hits[i];
  for (int i = 1; i <= n; ++i) {
    for (int j = pokeball; j >= balls[i]; --j) {
      for (int k = initial_hp - 1; k >= hits[i]; --k) {
        f[j][k] = max(f[j][k], f[j - balls[i]][k - hits[i]] + 1);
      }
    }
  }
  cout << f[pokeball][initial_hp - 1] << ' ';
  int cost_health = initial_hp;
  for (int k = 0; k <= initial_hp - 1; ++k) {
    if (f[pokeball][k] == f[pokeball][initial_hp - 1]) {
      cost_health = min(cost_health, k);
    }
  }
  cout << initial_hp - cost_health << endl;
  return 0;
}
